<?php if (!defined('THINK_PATH')) exit();?>
<div class="feeldesk-form-item <?php if(($crmsite["regionType"]) != "world"): ?>hidden<?php endif; ?>">

	<div class="feeldesk-form-block">

		<?php if(($crmsite["regionType"]) == "world"): if(($defineForm["is_required"]) == "0"): ?><span class="red required-icon">*</span><?php endif; endif; ?>

		<select name="<?php echo ($FormName); ?>[<?php echo ($form_name); ?>_defaultCountry]" lay-filter="select-country<?php echo $reg; ?>" lay-search>

			<option value=""><?php echo ($vo["form_description"]); ?></option>

			<?php if(is_array($country)): $i = 0; $__LIST__ = $country;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vc): $mod = ($i % 2 );++$i;?><option value="<?php echo ($vc["code"]); ?>" <?php if(($crmsite["regionType"]) != "world"): if(($vc["code"]) == "1"): ?>selected<?php endif; else: if(($crmsite["defaultCountry"]) == $vc["code"]): ?>selected<?php endif; endif; ?>><?php echo ($vc["name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>

		</select>

	</div>

</div>

<div class="feeldesk-form-item <?php if(($crmsite["regionType"]) == "world"): if(empty($crmsite["defaultProv"])): ?>hidden<?php endif; endif; ?>" >

	<div class="feeldesk-form-block">

		<?php if(($crmsite["regionType"]) != "world"): if(($defineForm["is_required"]) == "0"): ?><span class="red required-icon">*</span><?php endif; endif; ?>

		<select name="<?php echo ($FormName); ?>[<?php echo ($form_name); ?>_defaultProv]" lay-filter="select-province<?php echo $reg; ?>" id="province<?php echo $reg; ?>" lay-search>

			<option value=""><?php echo L('SELECT_PROVINCE');?></option>

			<?php if(($crmsite["regionType"]) == "world"): if(!empty($crmsite["defaultProv"])): if(is_array($province)): $i = 0; $__LIST__ = $province;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vc): $mod = ($i % 2 );++$i;?><option c-value="<?php echo ($vc["country_code"]); ?>" value="<?php echo ($vc["code"]); ?>" <?php if(($crmsite["defaultProv"]) == $vc["code"]): ?>selected<?php endif; ?>><?php echo ($vc["name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; endif; ?>

			<?php else: ?>

				<?php if(is_array($province)): $i = 0; $__LIST__ = $province;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vc): $mod = ($i % 2 );++$i;?><option c-value="<?php echo ($vc["country_code"]); ?>" value="<?php echo ($vc["code"]); ?>" <?php if(($crmsite["defaultProv"]) == $vc["code"]): ?>selected<?php endif; ?>><?php echo ($vc["name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; endif; ?>

		</select>

	</div>

</div>

<div class="feeldesk-form-item <?php if(empty($crmsite["defaultCity"])): ?>hidden<?php endif; ?>" >

	<div class="feeldesk-form-block">

		<select name="<?php echo ($FormName); ?>[<?php echo ($form_name); ?>_defaultCity]" lay-filter="select-city<?php echo $reg; ?>" id="city<?php echo $reg; ?>" lay-search>

			<option value=""><?php echo L('SELECT_CITY');?></option>

			<?php if(!empty($crmsite["defaultCity"])): if(is_array($city)): $i = 0; $__LIST__ = $city;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vc): $mod = ($i % 2 );++$i;?><option c-value="<?php echo ($vc["country_code"]); ?>" p-value="<?php echo ($vc["province_code"]); ?>" value="<?php echo ($vc["code"]); ?>" <?php if(($crmsite["defaultCity"]) == $vc["code"]): ?>selected<?php endif; ?>><?php echo ($vc["name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; endif; ?>

		</select>

	</div>

</div>

<div class="feeldesk-form-item <?php if(empty($crmsite["defaultArea"])): ?>hidden<?php endif; ?>" >

	<div class="feeldesk-form-block">

		<select name="<?php echo ($FormName); ?>[<?php echo ($form_name); ?>_defaultArea]" lay-filter="select-area<?php echo $reg; ?>" id="area<?php echo $reg; ?>" lay-search>

			<option value=""><?php echo L('SELECT_AREA');?></option>

			<?php if(!empty($crmsite["defaultArea"])): if(is_array($area)): $i = 0; $__LIST__ = $area;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vc): $mod = ($i % 2 );++$i;?><option value="<?php echo ($vc["code"]); ?>" <?php if(($crmsite["defaultArea"]) == $vc["code"]): ?>selected<?php endif; ?>><?php echo ($vc["name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; endif; ?>

		</select>

	</div>

</div>

<script type="text/javascript">

	layui.use('form',function()
	{
		var form = layui.form;

		form.on('select(select-country<?php echo $reg; ?>)',function(data)
		{
			var value = data.value;

			$.post("<?php echo U('AjaxRequest/getRegion');?>",{country_id:value,type:'province'},function(data)
			{
				if(data.code == 0)
				{
					var option = '<option value=""><?php echo L('SELECT_PROVINCE');?></option>';

					if(data.data.length > 0)
					{
						$.each(data.data,function(k,v)
						{
							option += "<option c-value='"+ v.country_code+"' value='"+v.code+"'>"+v.name+"</option>";
						});

						$('#province<?php echo $reg; ?>').html(option).parents('.feeldesk-form-item').slideDown('fast');
					}
					else
					{
						$('#province<?php echo $reg; ?>').html(option).parents('.feeldesk-form-item').slideUp('fast');
					}

					form.render('select')
				}
			});

			$('#city<?php echo $reg; ?>').html('<option value=""><?php echo L('SELECT_CITY');?></option>').parents('.feeldesk-form-item').slideUp('fast');

			$('#area<?php echo $reg; ?>').html('<option value=""><?php echo L('SELECT_AREA');?></option>').parents('.feeldesk-form-item').slideUp('fast');

			form.render('select');
		});

		form.on('select(select-province<?php echo $reg; ?>)',function(data)
		{
			var value = data.value;

			var cValue = $(data.elem).find("option[value='"+data.value+"']").attr('c-value');

			$.post("<?php echo U('AjaxRequest/getRegion');?>",{country_id:cValue,province_id:value,type:'city'},function(data)
			{
				if(data.code == 0)
				{
					var option = '<option value=""><?php echo L('SELECT_CITY');?></option>';

					if(data.data.length > 0)
					{
						$.each(data.data,function(k,v)
						{
							option += "<option c-value='"+ v.country_code+"' p-value='"+ v.province_code+"' value='"+v.code+"'>"+v.name+"</option>";
						});

						$('#city<?php echo $reg; ?>').html(option).parents('.feeldesk-form-item').slideDown('fast');
					}
					else
					{
						$('#city<?php echo $reg; ?>').html(option).parents('.feeldesk-form-item').slideUp('fast');
					}

					form.render('select')
				}
			});

			$('#area<?php echo $reg; ?>').html('<option value=""><?php echo L('SELECT_AREA');?></option>').parents('.feeldesk-form-item').slideUp('fast');

			form.render('select');
		});

		form.on('select(select-city<?php echo $reg; ?>)',function(data)
		{
			var value = data.value;

			var pValue = $(data.elem).find("option[value='"+data.value+"']").attr('p-value');

			var cValue = $(data.elem).find("option[value='"+data.value+"']").attr('c-value');

			$.post("<?php echo U('AjaxRequest/getRegion');?>",{country_id:cValue,province_id:pValue,city_id:value,type:'area'},function(data)
			{
				if(data.code == 0)
				{
					var option = '<option value=""><?php echo L('SELECT_AREA');?></option>';

					if(data.data.length > 0)
					{
						$.each(data.data,function(k,v)
						{
							option += "<option value='"+v.code+"'>"+v.name+"</option>";
						});

						$('#area<?php echo $reg; ?>').html(option).parents('.feeldesk-form-item').slideDown('fast');
					}
					else
					{
						$('#area<?php echo $reg; ?>').html(option).parents('.feeldesk-form-item').slideUp('fast');
					}

					form.render('select')
				}
			});
		});

	})

</script>